package cn.com.bluemoon.daps.standard.service.impl;

import cn.com.bluemoon.daps.api.model.RemoteDataModelService;
import cn.com.bluemoon.daps.api.model.RemoteDataModelTableService;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.standard.service.TopicCategoryDeletePredicate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 模型中关联主题分类的删除逻辑判断
 *
 * @author Jarod.Kong
 */
@Service
@Slf4j
public class ModelModuleTopicCategoryDeletePredicate implements TopicCategoryDeletePredicate {

    @Resource
    RemoteDataModelTableService remoteDataModelTableService;

    @Override
    public Result<String> predicate(String topicCategoryId) {
        // TODO: 2021/9/27  需要立航完善 返回规则，参考StandardModuleTopicCategoryDeletePredicate
        ResultBean<Boolean> topicTable = remoteDataModelTableService.getTopicTable(topicCategoryId);
        Boolean flag = topicTable.getCode() == 200 && topicTable.getContent() ? topicTable.getContent() : false;
        String message = flag ? "" : "模型已引用，不可删除";
        return Result.<String>builder().canDelete(flag).key(topicCategoryId).message(message).build();
    }
}
